$(function(){
   //添加数据
   getAllData();
   $('#searchbtn').click(function(){
       let val = $('#searchframe').val();
       if(val.trim()==''){
           return
       }
       let arr=[];
       let keyword=localStorage.getItem('keyword');
       if(keyword!=null){
           arr=JSON.parse(keyword)
       }
       arr.unshift(val);
       localStorage.setItem('keyword',JSON.stringify(arr))
       $('#searchframe').val('');
       getAllData();
   })

   function getAllData(){
    let arr =[];
    let keyword=localStorage.getItem('keyword');
    if(keyword!=null){
        arr=JSON.parse(keyword)
    }
    let str = '';
    for(let i =0;i<arr.length;i++){
        str+=`<span>${arr[i]}</span>`
        $('.history').html(str)
    }
   }

    //删除
    $('#delbtn').click(function(){
        if(confirm('删除？')){
            localStorage.clear();
            $('.history').html('')
        }
    })
})

$('.header .search>span').on('click',function(){
    history.go(-1)
})